package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.RobCaseManagementEntity;
import io.renren.modules.generator.service.RobCaseManagementService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;

/**
 * @author llawliet
 * @email llawliet@mail.sim.ac.cn
 * @date 2018-05-22 16:18:27
 */
@RestController
@RequestMapping("robcasemanagement")
public class RobCaseManagementController {
    @Autowired
    private RobCaseManagementService robCaseManagementService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("robcasemanagement:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<RobCaseManagementEntity> robCaseManagementList = robCaseManagementService.queryList(query);
        int total = robCaseManagementService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(robCaseManagementList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("robcasemanagement:info")
    public R info(@PathVariable("id") Integer id) {
        RobCaseManagementEntity robCaseManagement = robCaseManagementService.queryObject(id);

        return R.ok().put("robCaseManagement", robCaseManagement);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("robcasemanagement:save")
    public R save(@RequestBody RobCaseManagementEntity robCaseManagement) {
        robCaseManagementService.save(robCaseManagement);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("robcasemanagement:update")
    public R update(@RequestBody RobCaseManagementEntity robCaseManagement) {
        robCaseManagementService.update(robCaseManagement);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("robcasemanagement:delete")
    public R delete(@RequestBody Integer[] ids) {
        robCaseManagementService.deleteBatch(ids);

        return R.ok();
    }

}
